console.log(window.electronAPI);

// 测试单通道
const setButton = document.getElementById("btn");
const titleInput = document.getElementById("title");
setButton.addEventListener("click", () => {
  const title = titleInput.value;
  window.electronAPI.setTitle(title);
});

// 测试双通道
const btnFile = document.getElementById("btnFile");
const filePathElement = document.getElementById("filePath");

btnFile.addEventListener("click", async () => {
  const filePath = await window.electronAPI.openFile();
  filePathElement.innerText = filePath;
});


// 测试主进程向渲染进程通信
const counter = document.getElementById("counter");

window.electronAPI.handleCounter((event, value) => {
  const oldValue = Number(counter.innerText);
  const newValue = oldValue + value;
  counter.innerText = newValue;
  event.sender.send("counter-value", newValue);
});